﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NLog;


namespace planerka.Web.Controllers
{
    public class ErrorController : Controller
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();

        public ActionResult Index()
        {
            ViewData["resultMessage"] = TempData["resultMessage"];
            return View("Error");
        }

        // 404
        [HttpGet]
        public ActionResult Missing(string result)
        {

            HttpContext.Response.StatusCode = 404;
            HttpContext.Response.TrySkipIisCustomErrors = true;
            // Log the error
            Exception e = new Exception();
            
            LogEventInfo logEvent = new LogEventInfo();
            logEvent.Exception = e;
            logEvent.Level = LogLevel.Error;
            logEvent.Message = "404 error: " + result;
            logEvent.TimeStamp = DateTime.Now;
            logger.Log(logEvent);

            // Pass some optional information to the view
            //var model = ErrorViewModel();
            //model.Message = ...;
            //. . .
            // Render the view
            return View("404");
        }
    }
}
